package cn.com.basic.framework.datasource.config;

import cn.com.basic.framework.datasource.enums.DataSourceType;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

public class DynamicDataSourceContextHolder extends AbstractRoutingDataSource {
    private static final ThreadLocal<DataSourceType> contextHolder
            = new ThreadLocal<>();

    @Override
    protected Object determineCurrentLookupKey() {
        return contextHolder.get();
    }

    public static void setDataSource(DataSourceType value) {
        contextHolder.set(value);
    }

    public static void clearDataSource() {
        contextHolder.remove();
    }
}